Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update the regex for secrets scanning #2964

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

behara
Copy link
Contributor

@behara behara commented Sep 30, 2022

Description

When secret for Asymmetric Private Key is having spaces builtin regex is not able to detect. Below screenshot is an example when we apply builtin regex to a valid private key trivy doesn't detect the secret.

To Fix this modified regex to consider spaces also. I have also added a test case for this.

Screenshot from 2022-09-30 15-49-57

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@behara behara requested a review from knqyf263 as a code owner September 30, 2022 08:09
@CLAassistant
Copy link

CLAassistant commented Sep 30, 2022

CLA assistant check
All committers have signed the CLA.

@behara behara force-pushed the asymmRegex branch 2 times, most recently from c932189 to e4cb7ea Compare September 30, 2022 10:16
@behara behara changed the title WIP: update the regex for secrets scanning fix: update the regex for secrets scanning Sep 30, 2022
@@ -149,7 +149,7 @@ var builtinRules = []Rule{
Category: CategoryAsymmetricPrivateKey,
Title: "Asymmetric Private Key",
Severity: "HIGH",
Regex: MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY( BLOCK)?\s*?-----[\s]*?(?P<secret>[A-Za-z0-9=+/\\\r\n]+)[\s]*?-----\s*?END[ A-Z0-9_-]*? PRIVATE KEY( BLOCK)?\s*?-----`),
Regex: MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY( BLOCK)?\s*?-----[\s]*?(?P<secret>[ A-Za-z0-9=+/\\\r\n]+)[\s]*?-----\s*?END[ A-Z0-9_-]*? PRIVATE KEY( BLOCK)?\s*?-----`),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\s is better, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes @knqyf263 . Made the changes.

@knqyf263 knqyf263 merged commit 5e25182 into aquasecurity:main Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants